<template>
    <div class="big_box">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>资料管理</el-breadcrumb-item>
            <el-breadcrumb-item>文档列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-divider></el-divider>
        <el-form :model="Document" ref="_selectfrom">
            <el-row :gutter="5">
                <el-col :span="3">
                    <el-input placeholder="编号" v-model="Document.DocumentNumber"></el-input>
                </el-col>
                <el-col :span="3">
                    <el-input placeholder="姓名" v-model="Document.Title"></el-input>
                </el-col>
                <el-col :span="2">
                    <el-button  icon="el-icon-search" @click="formdata"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <el-row style="padding: 10px 0px">
            <el-col>
                <el-button-group>
                    <el-button class="buttongroup" type="danger" icon="el-icon-delete" @click="BatchDelete_event">批量删除</el-button>
                    <el-button class="buttongroup" type="success" icon="el-icon-circle-plus-outline" @click="AddDocument_dialog=true">添加</el-button>
                </el-button-group>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <el-table :data="tableData" border stripe style="width: 100%"  @selection-change="SelectionChange_event">
                    <el-table-column type="selection" width="40" align="center"></el-table-column>
                    <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                    <el-table-column fixed prop="DocumentNumber" label="文档编号" align="center" show-overflow-tooltip  width="120"></el-table-column>
                    <el-table-column fixed prop="Title" label="名称" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column prop="FileName " label="文件" align="center" show-overflow-tooltip >
                        <template slot-scope="slot">
                            <label v-if="slot.row.FileName == ''">无上传文件</label>
                            <label v-else>{{ slot.row.FileName }}</label>
                        </template>
                    </el-table-column>
                    <el-table-column prop="FileDescript" label="文件描述" align="center" show-overflow-tooltip >
                        <template slot-scope="slot">
                            <label v-if="slot.row.FileDescript == ''">空</label>
                            <label v-else>{{ slot.row.FileDescript }}</label>
                        </template>
                    </el-table-column>
                    <el-table-column prop="Remark" label="备注" align="center" show-overflow-tooltip  >
                        <template slot-scope="slot">
                            <label v-if="slot.row.Remark == ''">无</label>
                            <label v-else>{{ slot.row.Remark }}</label>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="250" align="center">
                        <template slot-scope="scope">
                            <el-button plain type="success" size="mini" @click="edit_event(scope.row)">编辑</el-button>
                            <el-button plain type="warning" size="mini" @click="enclosure_down(scope.row)">下载此文件</el-button>
                            <el-button plain type="danger" size="mini" @click="BatchDeleteOne_event(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
            <el-col :span="24">
                <div class="block">
                    <el-pagination
                            @size-change="formdata"
                            @current-change="formdata"
                            :current-page.sync="pagination.currentPage"
                            :page-sizes="pagination.pagesizes"
                            :page-size.sync="pagination.pagesize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total.sync="pagination.total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <el-dialog :visible.sync="AddDocument_dialog" width="80%" title="添加文档">
            <AddDocument></AddDocument>
        </el-dialog>

        <el-dialog :visible.sync="UpdataDocument_dialog.dialog" width="80%" title="修改文档信息">
            <UpdataDocument :document_-template="UpdataDocument_dialog.details" ></UpdataDocument>   
        </el-dialog>

    </div>
</template>

<script>
    import * as publicjs from "../../../public/Scriput/Public";
    import AddDocument from "./AddDocument";
    import UpdataDocument from "./UpdataDocument";

    export default {
        name: "Document",
        components: {
            AddDocument, UpdataDocument
        },
        data() {
            return {
                Document: {
                    DocumentNumber: '',
                    Title: '',
                },
                //表格数据
                tableData: [],
                //分页数据绑定
                pagination: {
                    currentPage: 1,
                    pagesizes: [10, 20, 30, 40, 50],
                    pagesize: 10,
                    total: 100
                },
                //多选列表的数据集合
                SelectMore_lis: [],
                AddDocument_dialog: false,
                UpdataDocument_dialog: {
                    dialog: false,
                    details: {},
                }
            }
        },
        created() {
            this.formdata()
            publicjs.http(this.$http, this.$message)
        },
        methods: {
            //初始化表格数据加载
            formdata() {
                let loadding = this.openLoading();
                this.$http.post('Document/GetDocumentDetail', {
                    currentPage: this.pagination.currentPage,
                    pagesize: this.pagination.pagesize,
                    Document: this.Document,
                }).then(res => {
                    loadding.close();
                    this.pagination.total = res.data.count
                    this.tableData = res.data.data
                }).catch(() => {
                    loadding.close();
                    this.$message.error('服务器异常,请联系管理员!')
                })
            },
            //表格单个删除
            BatchDeleteOne_event(obj) {
                this.SelectMore_lis.push(obj)
                this.BatchDelete_event()
            },
            //批量删除
            BatchDelete_event() {
                let idlis = []
                if (this.SelectMore_lis.length == 0) {
                    this.$message.warning('您还未选择需要删除的合同!')
                } else {
                    for (let i = 0; i < this.SelectMore_lis.length; i++) {
                        idlis.push(this.SelectMore_lis[i].Id)
                    }
                    this.$confirm('你确定要删除吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'error'
                    }).then(() => {
                        let loadding = this.openLoading();
                        this.$http.post('Document/DeleteDocumentContent', idlis).then(res => {
                            loadding.close();
                            if (res.data) {
                                this.$message.success('删除成功')
                                this.formdata()
                                this.SelectMore_lis = []
                            } else {
                                this.$message.warning('删除失败')
                            }
                        }).catch(() => {
                            loadding.close();
                            this.$message.error('服务器异常,请联系管理员!')
                        })
                    }).catch(() => {
                        this.$message.info('已取消!')
                        this.SelectMore_lis = []
                    })

                }
            },
            //文件下载
            enclosure_down(obj) {
                let option = { id: obj.Id, FileType: obj.FileType, Type: 0, FileName: obj.FileName }
                publicjs.DownLoadFile(option)
            },
            //表格数据序列号
            indexMethod(index) {
                return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
            },
            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            //编辑
            edit_event(obj) {
                this.UpdataDocument_dialog.dialog = true
                this.UpdataDocument_dialog.details = obj
            },
        }
    }
</script>

<style scoped>

</style>
